package source

import (
	"reflect"
)

type NEWS struct {
	Title      string
	Time       string
	ReadCount  string
	LastUpdate string
	Url        string
	Author     string
}

type Api interface {
	FetchNews(url string) ([]NEWS, error)
}

//全局源注册
var typeRegistry = make(map[string]reflect.Type)

//注册源
func registerType(elem interface{}) {
	t := reflect.TypeOf(elem).Elem()
	typeRegistry[t.Name()] = t
}

//实例源
func NewStruct(name string) (interface{}, bool) {
	elem, ok := typeRegistry[name]
	if !ok {
		return nil, false
	}
	return reflect.New(elem).Elem().Interface(), true
}
